/*
 * @Author: wangming
 * @Date: 2021-07-12 14:06:56
 * @LastEditors: wangming
 * @LastEditTime: 2021-09-02 14:51:49
 * @FilePath: /hanma-application-designer-fed/src/pageComponents/__components/hlCustom/index.js
 * @Description:自定义组件
 */
import myMixin from '@/pageComponents/myMixin';
import vmMixin from '@/pageComponents/vmMixin';
import { getRenderFun } from "@/utils/common.js";
export default {
    mixins: [myMixin, vmMixin],
    data() {
        return {
            state: null
        };
    },
    methods: {
        createData(data) {
            if (this.state === null && typeof data === 'object') {
                this.state = {}
                for (let key in data) {
                    this.$set(this.state, key, data[key])
                }
            }
        },
        setValue(v) {
            this.$emit('input', v)
        }
    },
    computed: {
        render() {
            return getRenderFun(this.config.__config.renderJsx)
        }
    },
    render(h) {
        if (this.isEdit) return <div>渲染组件(预览模式查看)</div>
        if (!this.config.__config.renderJsx) {
            return ''
        }
        let rootScope = this.vmEvents.exports
        let context = this.vmEvents.context
        return this.render(h, { context, vm: { value: this.value, setValue: this.setValue, createData: this.createData, state: this.state || {} } }, rootScope)
    }
};
